package com.hl.dao.impl;

import com.hl.bean.PanghuShop;
import com.hl.dao.StoreDao2;
import com.hl.util.DBUtils;

import java.util.List;
import java.util.Map;

public class StoreDaoImpl2 implements StoreDao2 {
    //门店新增
    @Override
    public int addStore(PanghuShop panghuShop) {
        int row = DBUtils.update("insert into panghu_shop (shop_name,shop_describe,shop_image,shop_phone,shop_province,shop_city,shop_district,shop_address,shop_longitude,shop_latitude,shop_status,shop_user_id,shop_account,shop_password,shop_sort,sales_volume) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",panghuShop.getShopName(),panghuShop.getShopDescribe(),panghuShop.getShopImage(),panghuShop.getShopPhone(),panghuShop.getShopProvince(),panghuShop.getShopCity(),panghuShop.getShopDistrict(),panghuShop.getShopAddress(),panghuShop.getShopLongitude(),panghuShop.getShopLatitude(),panghuShop.getShopStatus(),panghuShop.getShopUserId(),panghuShop.getShopAccount(),panghuShop.getShopPassword(),panghuShop.getShopSort(),panghuShop.getSalesVolume());
        return row;
    }

    //查询所有门店数量
    @Override
    public Long selectAllStoreCount() {
        Map<String,Object> map = DBUtils.queryOne("select count(*) as count from panghu_shop");
        Long count = (Long) map.get("count");
        return count;
    }

    //分页查询所有数据
    @Override
    public List<PanghuShop> selectAllStoreWithPage(int page, int size) {
        List<PanghuShop> shops = DBUtils.query("select * from panghu_shop limit ?,?",PanghuShop.class,(page - 1) * size,size);
        return shops;
    }

    //更新门店
    @Override
    public int updateStore(PanghuShop shop) {
        int row = DBUtils.update("update panghu_shop set shop_name = ?,shop_phone = ?,shop_province = ?,shop_city = ?,shop_district = ?,shop_address = ?,shop_longitude = ?,shop_latitude = ?,shop_describe = ? where shop_id = ?",shop.getShopName(),shop.getShopPhone(),shop.getShopProvince(),shop.getShopCity(),shop.getShopDistrict(),shop.getShopAddress(),shop.getShopLongitude(),shop.getShopLatitude(),shop.getShopDescribe(),shop.getShopId());
        return row;
    }
}
